﻿CREATE TABLE [dbo].[TagRelationships]
(
	[SourceTagId] BIGINT NOT NULL , 
    [DestinationTagId] BIGINT NOT NULL, 
    [RelationshipType] TINYINT NOT NULL, 
    PRIMARY KEY ([SourceTagId], [DestinationTagId], [RelationshipType]), 
    CONSTRAINT [FK_TagRelationships_ToSourceTag] FOREIGN KEY ([SourceTagId]) REFERENCES [Tag]([Id]), 
    CONSTRAINT [FK_TagRelationships_ToDestinationTag] FOREIGN KEY ([DestinationTagId]) REFERENCES [Tag]([Id])
)

GO

CREATE INDEX [IX_TagRelationships_SourceTagId] ON [dbo].[TagRelationships] ([SourceTagId], [RelationshipType])
GO

CREATE INDEX [IX_TagRelationships_DestinationTagId] ON [dbo].[TagRelationships] ([DestinationTagId], [RelationshipType])
